package com.xand.bt.terminal.ui.logger;

import java.util.ArrayList;
import java.util.List;

import javax.swing.table.AbstractTableModel;

public class LoggerTableModel extends AbstractTableModel {

	private static final long serialVersionUID = -5930062912294029665L;

	private static final int ROW_NUM			= 20;
	
	public static final int COLUMN_TIME 	= 0;
	public static final int COLUMN_TRACE 	= 1;
	
	private static final String[] COLUMN_NAMES = {"Time", "Trace"};
	
	private List<LoggerTrace> traces;
	
	public LoggerTableModel() {
		this.traces = new ArrayList<LoggerTrace>();
	}
	
	public int getColumnCount() {
		return COLUMN_NAMES.length;
	}

	public int getRowCount() {
		return traces.size();
	}
	
	public String getColumnName(int index) {
		String ret = COLUMN_NAMES[index];
		
		return ret;
	}

	public Object getValueAt(int rowIndex, int columnIndex) {
		String ret = "";
		
		LoggerTrace trace = this.traces.get(rowIndex);
		
		switch(columnIndex) {
		
			case COLUMN_TIME:
				ret = trace.getFormattedTimestamp();
				break;
				
			case COLUMN_TRACE:
				ret = trace.getTrace();
				break;
			
		}
		
		return ret;
	}
	
	public List<LoggerTrace> getTraces() {
		return this.traces;
	}
	
}
